package com.haozi.watchtomato.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.haozi.watchtomato.dao.TomatoDao;
import com.haozi.watchtomato.dto.TomatoDto;
import com.haozi.watchtomato.model.TomatoModel;
import com.haozi.watchtomato.service.ITomatoService;
import com.haozi.watchtomato.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author haozi
 * @date 2024/01/24
 */
@Service("TomatoServiceImpl")
@Slf4j
public class TomatoServiceImpl implements ITomatoService {

    @Autowired
    private TomatoDao tomatoDao;

    @Override
    public PageInfo<TomatoDto> queryTomatoList(TomatoModel model) {
        PageHelper.startPage(model.getPageNum(), model.getPageSize());
        List<TomatoDto> tomatoDtos = tomatoDao.queryTomatoList(model);
        PageInfo<TomatoDto> pageInfo = new PageInfo<>(tomatoDtos);
        return pageInfo;
    }

    @Override
    public int save(TomatoModel model) {
        model.setCodePrefix(DateUtils.dateTime());
        int result = tomatoDao.save(model);
        return result;
    }

    @Override
    public int update(TomatoModel model) {
        int result = tomatoDao.update(model);
        return result;
    }

    @Override
    public int delete(Integer id) {
        int result = tomatoDao.delete(id);
        return result;
    }

}
